package va;

import bufmgr.*;
import global.*;
import heap.*;
import index.IndexException;
import iterator.*;

import java.io.IOException;
import java.util.ArrayList;

public class BaseNNIndexScan extends BaseIndexScan {

    public ArrayList<RID> rids;
    public int count;
    public Vector100Dtype target;
    public int noOfBits;

    public BaseNNIndexScan(IndexType index,
                           String relName,
                           String indexName,
                           AttrType[] types,
                           short[] str_sizes,
                           int noInFields,
                           int noOutFields,
                           FldSpec[] outFields,
                           CondExpr[] selects,
                           int fldNum,
                           Vector100Dtype target,
                           int count,
                           int noOfBits) throws IndexException, HFException, HFBufMgrException, HFDiskMgrException, IOException, InvalidTupleSizeException, InvalidTypeException, FileScanException, TupleUtilsException, InvalidRelation, JoinsException, PageNotReadException, PredEvalException, UnknowAttrType, FieldNumberOutOfBoundException, WrongPermat {

        super(index, relName, indexName, types, str_sizes, noInFields, noOutFields, outFields, selects, fldNum);
        this.count = count;
        this.target = target;
        this.noOfBits = noOfBits;
    }

    /*
     * Retrieves the next tuple from the database, as defined by the RIDs acquired from the VAFileScan
     * General procedure:
     *  - The VAFileScan returned the RIDs associated with all the potential nearest neighbors
     *  - This function cycles through those RIDs and returns the actual tuple
     * @see iterator.Iterator#get_next()
     */
    @Override
    public Tuple get_next() throws Exception {

        if (this.rids.size() > 0) {
            RID rid = this.rids.remove(0);
            Tuple tuple = getRecordDirect(rid);
            return this.formatTuple(tuple);
        } else {
            return null;
        }
    }
}